<?php
/**
 * @program:   ABCD - ABCD-Central - http://reddes.bvsaude.org/projects/abcd
 * @copyright:  Copyright (C) 2009 BIREME/PAHO/WHO - VLIR/UOS
 * @file:      picklist.php
 * @desc:      Load , update and generates a picklist
 * @author:    Guilda Ascencio
 * @since:     20091203
 * @version:   1.0
 *
 * == BEGIN LICENSE ==
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as
 *    published by the Free Software Foundation, either version 3 of the
 *    License, or (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *  
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * == END LICENSE ==
*/
session_start();
if (!isset($_SESSION["permiso"])){
	header("Location: ../common/error_page.php") ;
}
include ("../config.php");
$lang=$_SESSION["lang"];

include("../lang/dbadmin.php");
include("../common/get_post.php");
//foreach ($arrHttp as $var => $value) 	echo "$var = $value<br>";
include("../common/header.php");
?>
<script language="javascript1.2" src="../dataentry/js/lr_trim.js"></script>
<script>

function CargarTabla(Tabla){
	url="picklist_edit.php?base=<?php echo $arrHttp["base"]?>&picklist="+Tabla+"&row=<?php echo $arrHttp["row"]?>&pl_type=<?php echo $arrHttp["pl_type"]?>&type=<?php echo $arrHttp["type"]?>"
    self.location.href=url
}

function EditCreate(){
	if (Trim(document.pl.picklist.value)==""){
		alert("<?php echo $msgstr["misfilen"].": ".$msgstr["picklistname"]?>")
		return
	}
	fn=document.pl.picklist.value
	bool=  /^[a-z][\w]+$/i.test(fn)
	bool=true
 	if (bool){

   	}
   	else {
      	alert("<?php echo $msgstr["errfilename"]?>");
      	return
   	}

	document.pl.submit()
}

function Pl_name(Tabla,DB){
		CargarTabla(Tabla)
		document.pl.picklist.value=Tabla
	}
function PickList_update(){
	row="<?php echo $arrHttp["row"]?>"
	name=self.document.pl.picklist.value
	if (window.top.frames.length>1){
		window.top.frames[2].valor=name
		window.top.frames[2].Asignar()
	}else{
		window.opener.valor=name
		window.opener.Asignar()
	}
	self.close()
}


function EliminarArchivo(){
	Tabla=Trim(document.pl.picklist.value)
	if (Tabla==""){
		alert("<?php echo $msgstr["selpldel"]?>")
		return
	}
    document.frmdelete.tab.value=Tabla
    document.frmdelete.path.value="def"
    document.frmdelete.submit()
}
</script>
<?php
echo "
	<div class=\"sectionInfo\"><div class=\"\">";
	

	
	echo "</div></div>
			<div class=\"breadcrumb\"><h3>".
				$msgstr["picklist"]. ": " . $arrHttp["base"]."
			</h3></div>
			<div class=\"actions\">";

	echo "<br /><br /><br /><a href=\"javascript:self.close()\" class=\"defaultButton\">";
	echo "<span><strong>". $msgstr["close"]."</strong></span></a>";

	echo "</div>



<div class=\"helper\">
<a href=../documentacion/ayuda.php?help=".$_SESSION["lang"]."/picklist_tab.html target=_blank>".$msgstr["help"]."</a>&nbsp &nbsp;";
if (isset($_SESSION["permiso"]["CENTRAL_EDHLPSYS"]))
	echo "<a href=../documentacion/edit.php?archivo=".$_SESSION["lang"]."/picklist_tab.html target=_blank>".$msgstr["edhlp"]."</a>";
echo "&nbsp; Script: picklist.php" ;
?>

	</div>
 <div class="middle form">
			<div class="formContent">
<form name=pl method=post action=picklist_edit.php>
<input type=hidden name=base value="<?php echo $arrHttp["base"]?>">
<input type=hidden name=row value="<?php echo $arrHttp["row"]?>">
<?php if (isset($arrHttp["pl_type"]) and $arrHttp["picklist"]=="ldr_06.tab") echo "<input type=hidden name=pl_type value=".$arrHttp["pl_type"].">\n"?>
<font face=arial size=1><?php echo $msgstr["editcreatepl"]?> <font color=darkred><?php echo $msgstr["updfdt"]?><font color=black><p>

<p><?php echo $msgstr["picklistname"]?>:<input type=text name=picklist value="<?php if (isset($arrHttp["picklist"]))echo $arrHttp["picklist"]?>">
&nbsp; &nbsp; <a id=botoes href=javascript:EditCreate()><?php echo $msgstr["editcreate"]?></a>
&nbsp; 
<a id=botoes href=javascript:EliminarArchivo()><?php echo $msgstr["delete"]?></a>
&nbsp;
<a id=botoes href=javascript:PickList_update()><?php echo $msgstr["updfdt"]?></a>
&nbsp; 
</form>
<form name=explora>
<input type=hidden name=base value=<?php echo $arrHttp["base"]?>>
<?
$Dir=$db_path.$arrHttp["base"]."/def/".$_SESSION["lang"];
$DirHttp="";
$handle = opendir($Dir);
echo "<font face=verdana size=2>";
$the_array=array();
while (false !== ($file = readdir($handle))) {
   if ($file != "." && $file != "..") {
   		if(is_file($Dir."/".$file)){
            if  (substr($file,-4,4)==".tab") $the_array[$file]=$file;
        }else

            $dirs[]=$file;
   }
}
closedir($handle);
$Dir=$db_path.$arrHttp["base"]."/def/".$lang_db;
$handle = opendir($Dir);
while (false !== ($file = readdir($handle))) {
   if ($file != "." && $file != "..") {
   		if(is_file($Dir."/".$file)){
            if  (substr($file,-4,4)==".tab")
            	if (!isset($the_array[$file]))$the_array[$file]=$file;
        }
   }
}
$wks="";
if (isset($arrHttp["wks"])) $wks="&wks=".$arrHttp["wks"];
sort ($the_array);
reset ($the_array);

while (list ($key, $val) = each ($the_array)) {
//	echo "key=".$key."<br>val=$val<br>wks=$wks<br>"  ;
   echo "<a href=javascript:Pl_name(\"$val\",\"".$arrHttp["base"]."\")>$val</a>; ";

}
?>
</td>
</table>

</form>
<div id="dwindow" style="position:relative;background-color:#ffffff;cursor:hand;left:0px;top:0px;height:200" onMousedown="initializedrag(event)" onMouseup="stopdrag()" onSelectStart="return false">
<div id="dwindowcontent" style="height:100%;">
<iframe name="cframe" id="cframe" src="" width=100% height=100% scrolling=yes name=fst></iframe>
</div>
</div>
<form name=frmdelete action=delete_file.php method=post>
<input type=hidden name=base value=<?php echo $arrHttp["base"]?>>
<input type=hidden name=path>
<input type=hidden name=tab>
</form>
</body></html>
<script>

</script>
